<!DOCTYPE html>
<html lang="cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>State的基本使用</title>
    <!-- 引入react引入核心库, 需要按顺序引入 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom, 用于支持react操作DOM -->
    <script type='text/javascript' src='../js/react-dom.development.js'></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type='text/javascript' src='../js/babel.min.js'></script>
</head>

<body>
    <div id="test"></div>

    <script type="text/babel">
        class Weather extends React.Component {
            state = { isHot: false }
            render() {
                console.log('render里的this:', this)
                return <h1 onClick={this.changeWeather}>今天天气很{this.state.isHot ? '炎热' : '凉爽'}</h1>
            }

            // 组件类中程序员定义的事件回调，必须写成赋值语句+箭头函数
            // 避免了this为undefined的问题
            changeWeather = ()=> {
                console.log('changeWeather里的this', this);
                const isHot = this.state.isHot
                this.setState({isHot:!isHot})
            }
        }
        ReactDOM.render(<Weather />, document.getElementById('test'))

    </script>
</body>

</html>